using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Publishing.Fields;
using Microsoft.SharePoint.Publishing.WebControls;
using System.Web.UI.WebControls;
using Samples.WebControls;


namespace Samples.CustomFieldControl
{

    public class MultimediaField : SPFieldMultiColumn
    {    
        
        public MultimediaField(SPFieldCollection fields, string fieldName)
            : base(fields, fieldName)
        { }

        public MultimediaField(SPFieldCollection fields,
                           string typeName,
                           string displayName)
            : base(fields, typeName, displayName)
        { }

        public override BaseFieldControl FieldRenderingControl
        {
            get
            {
                BaseFieldControl fldControl = new MultimediaWebControl();
                fldControl.FieldName = InternalName;
                return fldControl;
            }
        }


        public override string GetValidatedString(object value)
        {
            MultimediaFieldValue multimediafieldValue = value as MultimediaFieldValue;
            if (multimediafieldValue == null)
                return String.Empty;
            if (String.IsNullOrEmpty(multimediafieldValue.Url) || String.IsNullOrEmpty(multimediafieldValue.Height) || String.IsNullOrEmpty(multimediafieldValue.Width))
                throw new SPFieldValidationException(SPResource.GetString(Strings.MissingRequiredField));
            return value.ToString();
        }


        public override object GetFieldValue(string value)
        {
            if (string.IsNullOrEmpty(value))
                return null;

            MultimediaFieldValue multimediafieldValue = new MultimediaFieldValue(value);
            return multimediafieldValue;
        }

       
    }

      
}
